
let algorithm = 'aes-128-cbc'
let passwd = 'Y1qXtfbI2jlmlxkn'
let iv = '1234567890123456'
let cryptojs = require('crypto-js');
let {createDecipheriv} = require('crypto')

//加密
function Encrypte(str){
	let encryptedData = cryptojs.AES.encrypt(str, cryptojs.enc.Utf8.parse(passwd), {
	    iv: cryptojs.enc.Utf8.parse(iv),
	    mode: cryptojs.mode.CBC,
	    padding: cryptojs.pad.Pkcs7
	}).toString()
	return encryptedData;
}


//解密
function Decrypt(str=''){
	let decipher = createDecipheriv(algorithm, passwd, iv);
	decipher.setAutoPadding(true);
	let decryptData = decipher.update(str.toString(), 'base64', 'utf8');
	decryptData += decipher.final('utf8');
	return decryptData
}


module.exports={
	Encrypte,
	Decrypt
}